<?php

    $serv = new swoole_websocket_server('0.0.0.0',9502);

    $serv->on('open','OnOpen');

    function OnOpen($serv,$request){
        var_dump($request->fd,$request->get,$request->server);
        $serv->push($request->fd,"Hello world \n");
    }

    // listen the message

    $serv->on('message',function($serv,$frame){
        echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
        $serv->push($frame->fd,'Server: had got the message from '.$frame->fd);
    });

    $serv->on('close',function($serv,$fd){
        echo "Clien {$fd} closed";
    });
    $serv->start();